package com.ydh.company.controller;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.pojo.Condition;
import com.ydh.company.pojo.Notice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 通知公告类
 * @author ly
 * @version 1.0
 * @date 2020/4/30 19:57
 */


@RestController
@Api(tags = "通知公告测试API  5个")
@RequestMapping("/announcement")
public class AnnouncementController {


    @ApiOperation(value = "公告分页查询测试接口",notes = "通过输入的页码和页容量分页显示数据")
    @PostMapping("/selectByPage")
    public ResultData selectNoticeByPage(@RequestBody Condition condition){
        System.out.println("页容量是:"+condition.getPerSize());
        List<Notice> noticeList = new ArrayList<>();
        Notice notice = new Notice();
        notice.setNoticeId("1");
        notice.setContent("是一个通知");
        notice.setNoticeType("员工通知");
        notice.setCarousel(0l);
        noticeList.add(notice);
        return ResponseData.success(noticeList);
    }

    @ApiOperation(value = "按条件分页查询接口",notes = "用户输入条件查看通知公告")
    @PostMapping("/selectNoticeByCondition")
    public ResultData selectNoticeByCondition(@RequestBody Condition condition){

        System.out.println("查询条件是"+condition.getSelectValue());
        List<Notice> noticeList = new ArrayList<>();
        Notice notice = new Notice();
        notice.setNoticeId("2");
        notice.setContent("公司颁布的新规定");
        notice.setNoticeType("公司制度");
        notice.setCarousel(1l);
        noticeList.add(notice);
        return ResponseData.success(noticeList);
    }

    @ApiOperation(value = "公告添加测试接口",notes = "用户添加发布的公告和详细信息")
    @PostMapping("/add")
    public ResultData addNotice(@RequestBody Notice notice){
        System.out.println("通知的类型是:"+notice.getNoticeType());
        if (!notice.getNoticeId().equals("")) {
            return ResponseData.success("添加成功",null);
        }
        return ResponseData.error(400,"添加失败");
    }

    @ApiOperation(value = "公告删除测试接口",notes = "通过传入的通知id来删除通知")
    @PostMapping("/delete")
    public ResultData deleteNotice(@RequestBody Notice notice){

        System.out.println("删除的公告id是"+notice.getNoticeId());
        if (notice.getNoticeId().equals("1")) {
            return ResponseData.success("删除成功",null);
        }
        return ResponseData.error(400,"删除失败");
    }


    @ApiOperation(value = "修改通知测试接口",notes = "修改当前通知的文字轮播状态")
    @PostMapping("/update")
    public ResultData updateNotice(@RequestBody Notice notice){
        System.out.println("修改轮播状态:"+notice.getCarousel());
        if (notice.getNoticeId().equals("1")) {
            return ResponseData.success("修改成功",null);
        }
        return ResponseData.error(400,"修改失败");
    }

}
